package com.exam.ch8;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.TableColumn;

public class SimpleTable2 {
	
	public SimpleTable2(){
		
		JFrame jFrame = new JFrame();
		
		Object [][] payerInfo = {{"阿呆",new Integer(66),new Integer(32),new Integer(98),new Boolean(false)},
								{"阿瓜",new Integer(85),new Integer(69),new Integer(154),new Boolean(true)}};
		String [] names = {"姓名","语文","数学","总分","及格"};
		JTable table = new JTable(payerInfo, names);
		table.setPreferredScrollableViewportSize(new Dimension(550, 30));//设置表格的窗口大小
		table.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); //设置某个列宽调整时其他列宽的变化
		
		TableColumn column = null;
		for(int i=0;i<5;i++){
			column = table.getColumnModel().getColumn(i);
			if((i%2)==0){
				column.setPreferredWidth(150);
			}else{
				column.setPreferredWidth(50);
			}
		}
		
		JScrollPane scrollPane = new JScrollPane(table);
		jFrame.getContentPane().add(scrollPane,BorderLayout.CENTER);
		
		
		jFrame.setTitle("Simple Table");
		jFrame.pack();
		jFrame.setVisible(true);
		jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		
		
	}
	
	public static void main(String[] args) {
		
		new SimpleTable2();
		
	}

}
